/*
 *@本JS功能：题库管理
 *@本js作者：杨锡君
 *@编写时间：2017年11月20日
 */
$(function() {
    var Alert1 = new Alert();
    var confirm1 = new Confirm();
    var loading1 = new Loading();
    loading1.init();
    var $departNames = $("#departNames");
    var $tableBox = $(".tableBox");
    var $searchBtn = $(".searchBtn");
    var $fileName = $(".fileName");
    var $addTest = $(".addTest");//添加试题
    var $mb = $(".mb");
    var th = "<tr>" +
        "<th class=\"col-lg-1\"><input type=\"checkbox\" name=\"controlAll\" id=\"controlAll\" class=\"allCheck\"></th>" +
        "<th class=\"col-lg-4\">课程名称</th>" +
        "<th class=\"col-lg-4\">试题题目</th>" +
        "<th class=\"col-lg-2\">问题类型</th>" +
        "<th class=\"col-lg-1\">操作</th>" +
        "</tr>";

    function tabelModel(opt) {
        var questionType = opt.questionType;
        if(questionType == 1) {
            questionType = "单选题";
        }
        if(questionType == 2) {
            questionType = "判断题";
        }
        if(questionType == 3) {
            questionType = "填空题";
        }
        if(questionType == 4) {
            questionType = "简答题";
        }
        if(questionType == 5) {
            questionType = "多选题";
        }
        var optionMsg =  opt.optionMsg;
        if(optionMsg == ""){
            optionMsg = "undefined";
        }
        var quesName = opt.questionName.replace(/\(\+\)/g,"()");
        return "<tr data-num=\"0\">" +
            "<td class=\"col-lg-1\"><input data-questionid="+ opt.questionId +" data-courseid=" + opt.courseId + " value=\"0\" name=\"selecteds\" type=\"checkbox\" class=\"oneCheck\" /></td>" +
            "<td class=\"col-lg-4\" title='" + opt.courseName + "'>" + opt.courseName + "</td>" +
            "<td class=\"col-lg-4\" title='" + quesName + "'>" + quesName+ "</td>" +
            "<td class=\"col-lg-2\" title='" + questionType + "'>" + questionType + "</td>" +
            "<td class=\"col-lg-1\">" +
            "<a href=\"javascript:;\" data-questiontype="+ opt.questionType +" data-ansquescontent=\""+ escape(opt.ansquesContent) +"\" data-coursename="+ opt.courseName +" data-optionmsg=\""+ optionMsg +"\"  data-questionname=\""+ escape(opt.questionName) +"\"  data-questionid="+ opt.questionId +" data-courseid=" + opt.courseId + "  class=\"editBtn\">修改</a>" +
            "</td>" +
            "</tr>";
    }
    //文件模板
    var fileModel = "<div class=\"popup\">"
        +"<form id=\"uploadForm\" method=\"post\"  enctype=\"multipart/form-data\">"
        +"<div class=\"popup_box\">"
        +"<div class=\"popup_contenthead\">导入试题<img class=\"popup_img\" src=\"pc/images/ico_alertDel.png\"></div>"
        +"<div class=\"popup_content\">"
        +"<label class=\"fileBtn\" for=\"file\">点击选择文件</label>"
        +"<div class=\"fileName\"></div>"
        +"</div>"
        +"<div class=\"popup_btn\">"
        +"<button class=\"popup_confirm exportBtn exportBtnText hover-btn\">确定</button>"
        +"<a class=\"popup_close exportCancle hover-btn fr\">取消</a>"
        +"</div>"
        +"<div class=\"clear\"></div>"
        +"</div>"
        +"<input type=\"file\" name=\"file\" id=\"file\"  style=\"display: none;\" />"
        +"</form>"
        +"</div>";
    //添加问题模板
    var addTestModel = "<div class=\"popup testBox\">"
        +"<div class=\"popup_box\">"
        +"<div class=\"popup_contenthead\">添加试题<img class=\"popup_img\" src=\"pc/images/ico_alertDel.png\"></div>"
        +"<div class=\"popup_content\">"
        +"<div class=\"inputRight\"><label for=\"testType\">试题类型:&ensp;</label>"
        +"<select id=\"testType\" class=\"publicSelect\">"
        +"<option value=\"1\">单选题</option>"
        +"<option value=\"5\">多选题</option>"
        +"<option value=\"2\">判断题</option>"
        +"<option value=\"3\">填空题</option>"
        +"<option value=\"4\">简答题</option>"
        +"</select>"
        +"</div>"
        +"<div class=\"inputRight\"><label for=\"fillCourse\">对应课程:&ensp;</label>"
        +"<select id=\"fillCourse\" class=\"publicSelect\">"
        +"<option value=\"0\">请选择</option>"
        +"</select>"
        +"</div>"
        +"<div class=\"choiceBox\">"
        +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
        +"<textarea  class=\"testArea choice_title\" placeholder=\"这是一个试题题目\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
        +"</div>"
        +"<div><label for=\"testType\">选&emsp;&emsp;项:&ensp;</label>"
        +"<textarea   class=\"testArea choice_option\" placeholder=\"A答案#B答案#C答案#D答案\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>选项前加A,B,C,D等表示选项,每个选项用<i>“#”</i>分隔</div>"
        +"</div>"
        +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
        +"<textarea   class=\"testArea choice_answer\" placeholder=\"A答案\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>答案前加A,B,C,D等表示选项</div>"
        +"</div>"
        +"</div>"
        +"<div class=\"muchBox\"  style=\"display: none;\">"
        +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
        +"<textarea  class=\"testArea much_title\" placeholder=\"这是一个试题题目\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
        +"</div>"
        +"<div><label for=\"testType\">选&emsp;&emsp;项:&ensp;</label>"
        +"<textarea   class=\"testArea much_option\" placeholder=\"A答案#B答案#C答案#D答案\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>选项前加A,B,C,D等表示选项,每个选项用<i>“#”</i>分隔</div>"
        +"</div>"
        +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
        +"<textarea   class=\"testArea much_answer\" placeholder=\"AB\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>答案ABCD等表示选项</div>"
        +"</div>"
        +"</div>"
        +"<div class=\"fillBox\" style=\"display: none;\">"
        +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
        +"<textarea   class=\"testArea fill_title\" placeholder=\"这是一个试题题目(+),这是一个试题题目(+)这是一个试题题目(+)\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>输入题目时，<i>填空部分</i>用<i>英文括号(+)</i>代替</div>"
        +"</div>"
        +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
        +"<textarea   class=\"testArea fill_answer\" placeholder=\"答案1,答案2,答案3\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"</div>"
        +"</div>"
        +"<div class=\"checkBox\" style=\"display: none;\">"
        +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
        +"<textarea   class=\"testArea check_title\" placeholder=\"这是一个试题题目\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
        +"</div>"
        +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
        +"<span data-sex=\"T\" class=\"male radioCheck\">T</span><span data-sex=\"F\"  class=\"female radio\">F</span>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>T为正确，F为错误</div>"
        +"</div>"
        +"</div>"
        +"<div class=\"shortBox\" style=\"display: none;\">"
        +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
        +"<textarea   class=\"testArea short_title\" placeholder=\"这是一个试题题目\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
        +"</div>"
        +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
        +"<textarea   class=\"testArea short_answer\" placeholder=\"答案\"></textarea>"
        +"<div class=\"clear\"></div>"
        +"</div>"
        +"</div>"
        +"<div class=\"clear\"></div>"
        +"</div>"
        +"<div class=\"popup_btn\">"
        +"<a style=\"margin-left:100px;\" class=\"popup_confirm exportBtn hover-btn\">确定</a>"
        +"</div>"
        +"<div class=\"clear\"></div>"
        +"</div>"
        +"</div>";
    function editModel(opt){
        var str = "<div class=\"popup testBox\">"
            +"<div class=\"popup_box\">"
            +"<div class=\"popup_contenthead\">修改试题<img class=\"popup_img\" src=\"pc/images/ico_alertDel.png\"></div>"
            +"<div class=\"popup_content\">";
        var str1 = "";
        if(opt.type==1){
            str1 = "<div class=\"choiceBox\">"
                +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
                +"<textarea  class=\"testArea choice_title\" placeholder=\"这是一个试题题目\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
                +"</div>"
                +"<div><label for=\"testType\">选&emsp;&emsp;项:&ensp;</label>"
                +"<textarea  class=\"testArea choice_option\" placeholder=\"A答案#B答案#C答案#D答案\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>选项前加A,B,C,D等表示选项,每个选项用<i>“#”</i>分隔</div>"
                +"</div>"
                +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
                +"<textarea   class=\"testArea choice_answer\" placeholder=\"A答案\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>答案前加A,B,C,D等表示选项</div>"
                +"</div>"
                +"</div>";
        }
        if(opt.type==5){
            str1 = "<div class=\"muchBox\">"
                +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
                +"<textarea  class=\"testArea much_title\" placeholder=\"这是一个试题题目\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
                +"</div>"
                +"<div><label for=\"testType\">选&emsp;&emsp;项:&ensp;</label>"
                +"<textarea  class=\"testArea much_option\" placeholder=\"A答案#B答案#C答案#D答案\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>选项前加A,B,C,D等表示选项,每个选项用<i>“#”</i>分隔</div>"
                +"</div>"
                +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
                +"<textarea   class=\"testArea much_answer\" placeholder=\"A答案,B答案\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>答案前加A,B,C,D等表示选项</div>"
                +"</div>"
                +"</div>";
        }
        if(opt.type == 2){
            str1 = "<div class=\"checkBox\">"
                +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
                +"<textarea  class=\"testArea check_title\" placeholder=\"这是一个试题题目\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
                +"</div>"
                +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
                +"<span data-sex=\"T\" class=\"male radioCheck\">T</span><span data-sex=\"F\"  class=\"female radio\">F</span>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>T为正确，F为错误</div>"
                +"</div>"
                +"</div>"
        }
        if(opt.type == 3){
            str1 = "<div class=\"fillBox\">"
                +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
                +"<textarea   class=\"testArea fill_title\" placeholder=\"这是一个试题题目(+),这是一个试题题目(+)这是一个试题题目(+)\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>输入题目时，<i>填空部分</i>用<i>英文括号(+)</i>代替</div>"
                +"</div>"
                +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
                +"<textarea  class=\"testArea fill_answer\" placeholder=\"答案1,答案2,答案3\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>答案用<i>英文逗号</i>分隔</div>"
                +"</div>"
                +"</div>"
        }
        if(opt.type == 4){
            str1 = "<div class=\"shortBox\">"
                +"<div><label for=\"testType\">题&emsp;&emsp;目:&ensp;</label>"
                +"<textarea   class=\"testArea short_title\" placeholder=\"这是一个试题题目\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"<div class=\"tipInfo\"><i>提示：</i>输入题目时无需输入括号\"()\"</div>"
                +"</div>"
                +"<div><label for=\"testType\">答&emsp;&emsp;案:&ensp;</label>"
                +"<textarea   class=\"testArea short_answer\" placeholder=\"答案\"></textarea>"
                +"<div class=\"clear\"></div>"
                +"</div>"
                +"</div>"
        }
        var str2 = "<div class=\"clear\"></div>"
            +"</div>"
            +"<div class=\"popup_btn\">"
            +"<a class=\"popup_confirm exportBtn hover-btn\">确定</a>"
            +"<a class=\"popup_close exportCancle hover-btn fr\">取消</a>"
            +"</div>"
            +"<div class=\"clear\"></div>"
            +"</div>"
            +"</div>";
        return str + str1 + str2;
    }
    var searchJson;
    var classMana = {
        init: function() {
            this.bindEvent();
        },
        bindEvent: function() {
            var self = this;
            var json = {
                "pageNow": 1,
                "pageSize": 10
            };
            searchJson = json;
            self.tabelList(json);
//			删除
            $(".delTest").off("click").on("click", function() {
                self.delListEvent();
            });
//			搜索
            $searchBtn.off("click").on("click", function() {
                var courseId = $departNames.val();
                var jsonStr = {
                    "pageNow": 1,
                    "pageSize": 10
                };
                if(courseId != 0) {
                    jsonStr.courseId = courseId;
                }
                searchJson = jsonStr;
                self.tabelList(jsonStr);
            });
//			添加
            $addTest.off("click").on("click", function() {
                self.addTestEvent();
            });
        },
        addTestEvent:function(){
//			添加试题
            var self = this;
            $mb.show();
            $("body").append(addTestModel);
            $("#fillCourse").html($departNames.html());
            maxLengthLimit.init("testArea");
            //判断选择
            $(".male").off("click").on("click", function() {
                $(this).removeClass("radio").addClass("radioCheck");
                $(".female").removeClass("radioCheck").addClass("radio");
            });
            $(".female").off("click").on("click", function() {
                $(this).removeClass("radio").addClass("radioCheck");
                $(".male").removeClass("radioCheck").addClass("radio");
            });
            $("#testType").change(function(){
                if($(this).val() == 1){
                    $(".fillBox,.checkBox,.shortBox,.muchBox").hide();
                    $(".choiceBox").show();
                }
                if($(this).val() == 5){
                    $(".choiceBox,.fillBox,.checkBox,.shortBox").hide();
                    $(".muchBox").show();
                }
                if($(this).val() == 2){
                    $(".choiceBox,.fillBox,.shortBox,.muchBox").hide();
                    $(".checkBox").show();
                }
                if($(this).val() == 3){
                    $(".choiceBox,.checkBox,.shortBox,.muchBox").hide();
                    $(".fillBox").show();
                }
                if($(this).val() == 4){
                    $(".choiceBox,.fillBox,.checkBox,.muchBox").hide();
                    $(".shortBox").show();
                }

            });
            $(".popup_img").off("click").click(function() {
                $(".popup").remove();
                $(".mb").hide();
            });
//			提交
            $(".exportBtn").off("click").click(function() {
                var jsonStr = {};
                if($("#fillCourse").val() == 0){
                    Alert1.content = "请选择对应课程";
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if($("#testType").val() == 1){
                    var choice_title = $(".choice_title").val();
                    if(choice_title == ""){
                        Alert1.content = "请按照提示正确输入单选题题目";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".choice_option").val() == ""){
                        Alert1.content = "请按照提示正确输入单选题选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".choice_option").val().indexOf("A") ==-1){
                        Alert1.content = "请按照提示正确输入单选题选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".choice_option").val().indexOf("#") ==-1){
                        Alert1.content = "请按照提示正确输入单选题选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".choice_option").val().indexOf("#B") ==-1){
                        Alert1.content = "请按照提示正确输入单选题选项，至少两个选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".choice_answer").val() == ""){
                        Alert1.content = "请按照提示正确输入单选题答案";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    jsonStr.ansquesContent = $(".choice_answer").val();
                    jsonStr.questionType = 1;
                    jsonStr.optionMsg = $(".choice_option").val();
                    jsonStr.questionName = $(".choice_title").val();

                }
                if($("#testType").val() == 5){
                    var choice_title = $(".much_title").val();
                    if(choice_title == ""){
                        Alert1.content = "请按照提示正确输入多选题题目";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".much_option").val() == ""){
                        Alert1.content = "请按照提示正确输入多选题选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".much_option").val().indexOf("A") ==-1){
                        Alert1.content = "请按照提示正确输入多选题选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".much_option").val().indexOf("#") ==-1){
                        Alert1.content = "请按照提示正确输入选择题选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".much_option").val().indexOf("#B") ==-1){
                        Alert1.content = "请按照提示正确输入多选题选项，至少两个选项";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".much_answer").val() == ""){
                        Alert1.content = "请按照提示正确输入多选题答案";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    jsonStr.ansquesContent = $(".much_answer").val();
                    jsonStr.questionType = 5;
                    jsonStr.optionMsg = $(".much_option").val();
                    jsonStr.questionName = $(".much_title").val();

                }
                if($("#testType").val() == 2){
                    if($(".check_title").val() == ""){
                        Alert1.content = "请按照提示正确输入判断题题目";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    jsonStr.ansquesContent = $(".radioCheck").attr("data-sex");
                    jsonStr.questionType = 2;
                    jsonStr.optionMsg = "";
                    jsonStr.questionName = $(".check_title").val();

                }
                if($("#testType").val() == 3){
                    if($(".fill_title").val() == ""){
                        Alert1.content = "请按照提示正确输入填空题题目";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".fill_title").val().indexOf("(+)") == -1){
                        Alert1.content = "请按照提示正确输入填空题题目";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".fill_answer").val() == ""){
                        Alert1.content = "请按照提示正确输入填空题答案";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    jsonStr.ansquesContent = $(".fill_answer").val();
                    jsonStr.questionType = 3;
                    jsonStr.optionMsg = "";
                    jsonStr.questionName = $(".fill_title").val();
                }
                if($("#testType").val() == 4){
                    if($(".short_title").val() == ""){
                        Alert1.content = "请按照提示正确输入简答题题目";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if($(".short_answer").val() == ""){
                        Alert1.content = "请输入简答题答案";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    jsonStr.ansquesContent = $(".short_answer").val();
                    jsonStr.questionType = 4;
                    jsonStr.optionMsg = "";
                    jsonStr.questionName = $(".short_title").val();
                }
                jsonStr.operationType = 1;
                jsonStr.courseId = Number($("#fillCourse").val());
                loading1.show();
                $.ajax({
                    type:"post",
                    url:"addQuestion",
                    async:true,
                    data:{
                        "jsonStr":JSON.stringify(jsonStr)
                    },
                    success:function(msg){
                        loading1.hide();
                        msg = JSON.parse(msg);
                        if(msg.result == "success"){
                            Alert1.content = "添加试题成功";
                            Alert1.success = function(){
                                var json = JSON.stringify({
                                    "pageName": "testBaseMana"
                                });
                                window.location.href = "skipPage?jsonStr=" + json;
                                // self.tabelList(searchJson);
                                // $(".popup").remove();
                                // $(".mb").hide();
                            };
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }else{
                            Alert1.content = msg.msg;
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                    }
                });
            });

        },
        fileEvent: function() {
            var res = "";
            $("#file").off("change").change(function() {
                if($("#file").val()!=""){
                    var type = $(this).val().substring($(this).val().lastIndexOf(".")).toLowerCase(); // 取文件格式后缀名
                    if(type != ".xls" && type != ".xlsx") {
                        $("#file").val("");
                        Alert1.content = "请上传Excel文件，谢谢合作！";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    } else {
                        var filename = $(this).val().substring($(this).val().lastIndexOf("\\")+1);
                        $(".fileName").html("已选:"+filename);
                        return true;
                    }
                }else{
                    $("#file").val("");
                    $(".fileName").html("");
                }
            });
        },
        tabelList: function(jsons) {
            var self = this;
            var json = JSON.stringify(jsons);
            loading1.show();
            $.ajax({
                type: "post",
                url: "getAllQuestionListByPost",
                data: {
                    "jsonStr": json
                },
                async: true,
                success: function(msg) {
                    loading1.hide();
                    msg = JSON.parse(msg);
                    $tableBox.empty();
                    self.exportStuEvent();
                    if(msg.result == "success"){
                        if(msg.questionList != null && msg.questionList.length != 0) {
                            //列表
                            var tabel = "";
                            $.map(msg.questionList, function(opt) {
                                tabel += tabelModel(opt);
                            });
                            $tableBox.append(th + tabel);
                            self.allCheckEvent();
                            self.editTestEvent();

                        } else {
                            var trImg = "<tr><td colspan='5'><img style='margin: 80px auto 20px;' src='pc/images/ico_noneData.png'><p style='font-size:26px;color:#8a8a8a;width:100%;text-align:center;'>暂无数据</p></td></tr>";
                            $tableBox.append(th + trImg)
                        }
                        var sumpage = msg.totalPage;
                        if(sumpage == 0){
                            sumpage = 1;
                        }
                        var nowpage = 1;
                        var pagenumber = 10;
                        $(".tcdPageCode").createPage({
                            pageCount: sumpage, //总页数
                            current: nowpage, //当前页数
                            pageNumber: pagenumber, //每页显示数量
                            backFn: function(p) {
                                nowpage = p;
                                if(nowpage >= sumpage) {
                                    nowpage = sumpage;
                                }
                                var jsonStr = jsons;
                                jsonStr.pageNow = nowpage;
                                loading1.show();
                                $.ajax({
                                    type: "post",
                                    url: "getAllQuestionListByPost",
                                    data: {
                                        "jsonStr": JSON.stringify(jsonStr)
                                    },
                                    async: true,
                                    success: function(msg) {
                                        loading1.hide();
                                        msg = JSON.parse(msg);
                                        //列表
                                        $tableBox.empty();
                                        var tabel = "";
                                        $.map(msg.questionList, function(opt) {
                                            tabel += tabelModel(opt);
                                        });
                                        $tableBox.append(th + tabel);
                                        self.allCheckEvent();
                                        self.editTestEvent();
                                    }
                                });
                            }
                        });
                        //获取课程
                        $departNames.html("<option value=\"0\">请选择</option>");
                        if(msg.courseList.length!=0){
                            $.map(msg.courseList, function(opt) {
                                $departNames.append("<option value=" + opt.courseId + ">" + opt.courseName + "</option>");
                                $("#fillCourse").append("<option value=" + opt.courseId + ">" + opt.courseName + "</option>");
                            });
                            if(msg.searchObejct!=undefined){
                                $departNames.val(msg.searchObejct.courseId);
                            }
                        }

                    }else{
                        if(msg.failMsg != undefined){
                            if(msg.failMsg == "暂无权限"){
                                parent.location.reload(true);
                            }else{
                                Alert1.content = msg.failMsg;
                                Alert1.init();
                                Alert1.show();
                            }
                        }else{
                            if (msg.errorMsg != "" && msg.errorMsg != undefined) {
                                Alert1.content = msg.errorMsg;
                            } else {
                                Alert1.content = "获取失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }
                    }

                }
            });

        },
        editTestEvent:function(){
            //修改试题
            var self = this;
            $(".editBtn").off("click").click(function() {
                $(".mb").show();
                if($(".popup").length!=0){
                    $(".popup").remove();
                }
                var courseId = $(this).attr("data-courseid");
                var questionId = $(this).attr("data-questionid");
                var questionType = $(this).attr("data-questiontype");
                var ansquesContent = unescape($(this).attr("data-ansquescontent")).replace(/\<br\>/ig,"\n");
                var questionname = unescape($(this).attr("data-questionname")).replace(/\<br\>/ig,"\n");
                var optionMsg = $(this).attr("data-optionmsg").replace(/\<br\>/ig,"\n");
                var obj = {
                    "type":questionType,
                    "questionname":questionname,
                    "ansquesContent":ansquesContent
                };
                var str = editModel(obj);
                $("body").append(str);
                maxLengthLimit.init("testArea");
//				X
                $(".popup_img").off("click").click(function() {
                    $(".popup").remove();
                    $(".mb").hide();
                });
                //取消
                $(".exportCancle").off("click").click(function() {
                    $(".popup").remove();
                    $(".mb").hide();
                });
//				赋值
                if(optionMsg == "undefined"){
                    $(".testArea").eq(0).val(questionname);
                    $(".testArea").eq(1).val(ansquesContent);
                }else{
                    $(".testArea").eq(0).val(questionname);
                    $(".testArea").eq(1).val(optionMsg);
                    $(".testArea").eq(2).val(ansquesContent);
                }

                if(questionType == 2){
                    //判断选择
                    $(".male").off("click").on("click", function() {
                        $(this).removeClass("radio").addClass("radioCheck");
                        $(".female").removeClass("radioCheck").addClass("radio");
                    });
                    $(".female").off("click").on("click", function() {
                        $(this).removeClass("radio").addClass("radioCheck");
                        $(".male").removeClass("radioCheck").addClass("radio");
                    });
                }
                if(ansquesContent == "T"){
                    $(".male").removeClass("radio").addClass("radioCheck");
                    $(".female").removeClass("radioCheck").addClass("radio");
                }else{
                    $(".female").removeClass("radio").addClass("radioCheck");
                    $(".male").removeClass("radioCheck").addClass("radio");
                }
//				修改确认
                $(".exportBtn").off("click").click(function() {
                    var jsonStr = {};
                    if(questionType == 1){
                        var choice_title = $(".choice_title").val();
                        if(choice_title == ""){
                            Alert1.content = "请按照提示正确输入单选题题目";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".choice_option").val() == ""){
                            Alert1.content = "请按照提示正确输入单选题选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".choice_option").val().indexOf("A") ==-1){
                            Alert1.content = "请按照提示正确输入单选题选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".choice_option").val().indexOf("#") ==-1){
                            Alert1.content = "请按照提示正确输入单选题选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".choice_option").val().indexOf("#B") ==-1){
                            Alert1.content = "请按照提示正确输入单选题选项,至少输入两个选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".choice_answer").val() == ""){
                            Alert1.content = "请按照提示正确输入单选题答案";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        jsonStr.ansquesContent = $(".choice_answer").val();
                        jsonStr.questionType = 1;
                        jsonStr.optionMsg = $(".choice_option").val();
                        jsonStr.questionName = $(".choice_title").val();

                    }
                    if(questionType == 5){
                        var choice_title = $(".much_title").val();
                        if(choice_title == ""){
                            Alert1.content = "请按照提示正确输入多选题题目";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".much_option").val() == ""){
                            Alert1.content = "请按照提示正确输入多选题选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".much_option").val().indexOf("A") ==-1){
                            Alert1.content = "请按照提示正确输入多选题选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".much_option").val().indexOf("#") ==-1){
                            Alert1.content = "请按照提示正确输入多选题选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".much_option").val().indexOf("#B") ==-1){
                            Alert1.content = "请按照提示正确输入多选题选项,至少输入两个选项";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".much_answer").val() == ""){
                            Alert1.content = "请按照提示正确输入多选题答案";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        jsonStr.ansquesContent = $(".much_answer").val();
                        jsonStr.questionType = 5;
                        jsonStr.optionMsg = $(".much_option").val();
                        jsonStr.questionName = $(".much_title").val();

                    }
                    if(questionType == 2){
                        if($(".check_title").val() == ""){
                            Alert1.content = "请按照提示正确输入判断题题目";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        jsonStr.ansquesContent = $(".radioCheck").attr("data-sex");
                        jsonStr.questionType = 2;
                        jsonStr.optionMsg = "";
                        jsonStr.questionName = $(".check_title").val();

                    }
                    if(questionType == 3){
                        if($(".fill_title").val() == ""){
                            Alert1.content = "请按照提示正确输入填空题题目";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".fill_title").val().indexOf("(+)") == -1){
                            Alert1.content = "请按照提示正确输入填空题题目";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".fill_answer").val() == ""){
                            Alert1.content = "请按照提示正确输入填空题答案";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        jsonStr.ansquesContent = $(".fill_answer").val();
                        jsonStr.questionType = 3;
                        jsonStr.optionMsg = "";
                        jsonStr.questionName = $(".fill_title").val();
                    }
                    if(questionType == 4){
                        if($(".short_title").val() == ""){
                            Alert1.content = "请按照提示正确输入简答题题目";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        if($(".short_answer").val() == ""){
                            Alert1.content = "请输入简答题答案";
                            Alert1.init();
                            Alert1.show();
                            return false;
                        }
                        jsonStr.ansquesContent = $(".short_answer").val();
                        jsonStr.questionType = 4;
                        jsonStr.optionMsg = "";
                        jsonStr.questionName = $(".short_title").val();
                    }
                    jsonStr.operationType = 2;
                    jsonStr.courseId = Number(courseId);
                    jsonStr.questionId = Number(questionId);
                    loading1.show();
                    $.ajax({
                        type:"post",
                        url:"addQuestion",
                        async:true,
                        data:{
                            "jsonStr":JSON.stringify(jsonStr)
                        },
                        success:function(msg){
                            loading1.hide();
                            msg = JSON.parse(msg);
                            if(msg.result == "success"){
                                Alert1.content = "修改试题成功";
                                Alert1.success = function(){
                                    var json = JSON.stringify({
                                        "pageName": "testBaseMana"
                                    });
                                    window.location.href = "skipPage?jsonStr=" + json;
                                    // self.tabelList(searchJson);
                                    // $(".popup").remove();
                                    // $(".mb").hide();
                                };
                                Alert1.init();
                                Alert1.show();
                                return false;
                            }else{
                                Alert1.content = msg.msg;
                                Alert1.init();
                                Alert1.show();
                                return false;
                            }
                        }
                    });
                });
            });
        },
        exportStuEvent: function() {
            var self = this;
//			导入
            $(".specialBtn").off("click").click(function() {
                $(".mb").show();
                if($(".popup").length!=0){
                    $(".popup").remove();
                }
                $("body").append(fileModel);
                var flag = self.fileEvent();
                //	批量导入
                $(".exportBtnText").off("click").click(function () {
                    if($(".fileName").html() == ""){
                        Alert1.content = "请上传文件";
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }else{
                        $("#uploadForm").off("submit").submit(function(event) {
                            var formData = new FormData(this);
                            confirm1.content = "是否确认上传文件？";
                            confirm1.success = function() {
                                loading1.show();
                                setTimeout(function (args) {
                                    $.ajax({
                                        url: 'imQuestion',
                                        type: 'post',
                                        data: formData,
                                        async: false,
                                        cache: false,
                                        contentType: false,
                                        processData: false,
                                        success: function(msg) {
                                            loading1.hide();
                                            msg = JSON.parse(msg);
                                            if(msg.result == "success") {
                                                Alert1.content = "上传文件成功";
                                                Alert1.success = function() {
                                                    $("#file").val();
                                                    var json = JSON.stringify({
                                                        "pageName": "testBaseMana"
                                                    });
                                                    window.location.href = "skipPage?jsonStr=" + json;
                                                };
                                                Alert1.init();
                                                Alert1.show();
                                            }else{
                                                Alert1.content = msg.errMsg;
                                                $("#file").val("");
                                                $(".fileName").html("");
                                                Alert1.init();
                                                Alert1.show();
                                            }
                                            return false;
                                        }

                                    });
                                    return false;
                                },1000);
                                return false;
                            };
                            confirm1.init();
                            confirm1.show();
                            return false;
                        });

                    }
                });
//				取消
                $(".exportCancle").off("click").click(function() {
                    $(".popup").remove();
                    $(".mb").hide();
                });
//				X
                $(".popup_img").off("click").click(function() {
                    $(".popup").remove();
                    $(".mb").hide();
                });
            });
        },
        delListEvent: function() {
//			删除
            if($(".oneCheck[value=1]").length == 0) {
                Alert1.content = "请选择要删除的试题";
                Alert1.init();
                Alert1.show();
            } else {
                var list = [];
                for(var i = 0; i < $(".oneCheck[value=1]").length; i++) {
                    list.push($(".oneCheck[value=1]").eq(i).attr("data-questionid"));
                }
                confirm1.content = "确定删除这<a style='color:#c82011;text-decoration:underline;font-weight:bolder;' href='javascript:;'>" + $(".oneCheck[value=1]").length + "</a>个试题吗"
                confirm1.success = function() {

                    var jsonStr = JSON.stringify(list);
                    loading1.show();
                    $.ajax({
                        type: "post",
                        url: "delQuestions",
                        async: true,
                        data: {
                            "jsonStr":jsonStr
                        },
                        success: function(msg) {
                            loading1.hide();
                            msg = JSON.parse(msg);
                            if(msg.result == "success"){
                                Alert1.content = "删除成功";
                                Alert1.success = function () {
                                    var json = JSON.stringify({
                                        "pageName":"testBaseMana"
                                    });
                                    window.location.href = "skipPage?jsonStr="+json;
                                };
                                Alert1.init();
                                Alert1.show();
                            }else{
                                Alert1.content = "删除失败";
                                Alert1.init();
                                Alert1.show();
                            }

                        },
                        error: function(err) {

                        }

                    });
                };
                confirm1.init();
                confirm1.show();

            }
        },
        allCheckEvent: function() {
            //全选
            allCheck.init("controlAll", "oneCheck");
        }
    };
    classMana.init();
});